/*!
 * Header file corresponding to the movies list. (movies.cpp)
 * THIS FILE IS NOT USED FOR THE MOMENT
 * @author Mazzer Yannis, Calingarayar Martial
 */
#ifndef _MOVIES_H
#define _MOVIES_H

#include <QList>
#include <QSqlDatabase>
#include <QDataWidgetMapper>
#include <QSqlTableModel>
#include "../liteconnector/liteconnector.h"
#include "movie/movie.h"

/*!
 * Declaration of the MovieList structure as a QList of a pointer to Movie.
 */
typedef QList<Movie *> MovieList;

/*!
 * This class gather all informations about a movies list.
 */
class Movies : public QSqlTableModel
{
    Q_OBJECT
    public:
/*!
 * Movies class construcor.
 * @param &db
 * @param parent A pointer to the parent which calle the constructor.
 */
	Movies(QSqlDatabase &db, QWidget *parent = 0);

/*!
 * Movies class destructor.
 */
	~Movies();

/*!
 * This function returns the information about the movie.
 * @param &movieNumber Number of film that we want the information.
 * @return The information about the film.
 */
	Movie *getMovie(const int &movieNumber);

/*!
 * This function returns the information about the movie.
 * @param &movieIndex The index of the movie wanted.
 * @return The information about the film.
 */
	Movie *getMovie(const QModelIndex &movieIndex);

/*!
 * This function returns the list of movies.
 * @return List of movies.
 */
	MovieList getMovieList();

/*!
 *
 * @param &idx
 * @return
 */
	QModelIndex persistentIndexModel(const int &idx);

/*!
 * This function adds a new movie to the list.
 * @param newMovie The name of the new movie.
 * @param ok is set to false if the movie is already in the list.
 * @return Index of movie if it isn't new otherwise 0.
 */
    int addMovie(Movie *newMovie, bool ok = true);

/*!
 *This function remove a movie to the list.
 * @param oldMovie The old movie you wish remove to the list.
 */
	void removeMovie(Movie *oldMovie);

    public slots:
	void updateMovieList();

    private slots:

	void updateDbRow(int idx, QSqlRecord record);
	void resetIndexes();

    private:
	MovieList movs;
	QModelIndexList persistentLinks;
};

#endif // _MOVIES_H
